<?php
/**
 * @author 	 	 faithsmine@gmail.com
 * @copyright		 www
 * @version		 1.0
 * @name 		 list.action.php
 * @todo 		 列表处理程序处理
 * @final 		 2009-12-10
 */
!defined("IN_YCTOOL") && exit();
require_once(DIR_COMM . 'cuthtml.func.php');
//获取POST/GET方法提交的变量
$operation = isset($_GET['operation']) ? $_GET['operation'] : "";
$type = isset($_GET['type']) ? $_GET['type'] : "";
$theurl = "admin.php?action=$action&operation=$operation&type=$type";
$posturl = "admin.php?action=post&operation=$operation&type=$type";
$viewurl = "admin.php?action=view&operation=$operation&type=$type";
$whereY = 1;

// |< ajax 处理 
$ajaxaction	= isset($_GET['ajaxaction']) ? $_GET['ajaxaction'] : "";
$ajax		= isset($_POST['ajax']) ? $_POST['ajax'] : "";
//不需要登录的处理
if($ajaxaction == 'ajax')
{
    if($ajax == 'uproles')
    { 
        $uroles = isset($_POST['uroles']) ? $_POST['uroles'] : "";
        $uid = isset($_POST['uid']) ? $_POST['uid'] : "";
        //file_put_contents('C:/b.txt', $ajax.'/'.$ajaxaction.' / '.$uroles.' / '. $uid);
	if(db::update(DB_TABLEPRE . 'user_basic', array('roles' => $uroles), 'userid = '.$uid)) { echo 1;};
	exit;
    }

   if($ajax == 'upcset')
    { 
        $cset = isset($_POST['cset']) ? $_POST['cset'] : "";
        $clsid = isset($_POST['clsid']) ? $_POST['clsid'] : "";
        
	if(db::update(DB_TABLEPRE . 'products_cls', array('cset' => $cset), 'clsid = '.$clsid)) { echo 1;};
	exit;
    }
}
// ajax 处理 >|

//搜索功能参数  
if($operation == 'news')
{
    $ntitle = isset($_POST['ntitle']) ? $_POST['ntitle'] : $_GET['ntitle'];
    $whereY .=' AND ntitle LIKE \'%' . $ntitle . '%\'';
    $theurl .= "&ntitle=$ntitle";

    $nposttime = isset($_POST['nposttime']) ? $_POST['nposttime'] : $_GET['nposttime'];
    $whereY .=' AND nposttime LIKE \'%' . $nposttime . '%\'';
    $theurl .= "&nposttime=$nposttime";

    $nuname = isset($_POST['nuname']) ? $_POST['nuname'] : $_GET['nuname'];
    $whereY .=' AND nuname LIKE \'%' . $nuname . '%\'';
    $theurl .= "&nuname=$nuname";
}

if($operation == 'products')
{
    $pname = isset($_POST['pname']) ? $_POST['pname'] : $_GET['pname'];
    $whereY .=' AND pname LIKE \'%' . $pname . '%\'';
    $theurl .= "&pname=$pname";

    $pclass = isset($_POST['pclass']) ? $_POST['pclass'] : $_GET['pclass'];
    $whereY .=' AND pclass LIKE \'%' . $pclass . '%\'';
    $theurl .= "&pclass=$pclass";

    $pprice1 = isset($_POST['pprice1']) ? $_POST['pprice1'] : $_GET['pprice1'];
    $pprice2 =isset($_POST['pprice2']) ? $_POST['pprice2'] : $_GET['pprice2'];
    if (trim($pprice1) != '' && trim($pprice2) != '')
    {
        $whereY .=' AND pprice BETWEEN \'' . $pprice1 . '\' AND \'' . $pprice2 . '\'';
        $theurl .= "&pprice1=$pprice1&pprice2=$pprice2";
    }
    $pcls_arrs = db::getAll(DB_TABLEPRE . 'products_cls', '*', 'ctype=1 AND cset = 1 AND paid = 0'); 
    foreach($pcls_arrs as $val)
    {
        $pcls_arrs2[$val['clsid']] = $val['clsname']; 
    }
}
if($operation == 'user')
{
    $uname = isset($_POST['uname']) ? $_POST['uname'] : $_GET['uname'];
    $whereY .=' AND username LIKE \'%' . $uname . '%\'';
    $theurl .= "&uname=$uname";

    $tel = isset($_POST['tel']) ? $_POST['tel'] : $_GET['tel'];
    $whereY .=' AND tel LIKE \'%' . $tel . '%\'';
    $theurl .= "&tel=$tel";
}
if($operation == 'pcls')
{
    $clsname = isset($_POST['clsname']) ? $_POST['clsname'] : $_GET['clsname'];
    $whereY .=' AND clsname LIKE \'%' . $clsname . '%\''. ' AND ctype = 1';
    $theurl .= "&clsname=$clsname";
    $pcls_arrs = db::getAll(DB_TABLEPRE . 'products_cls', '*', 'ctype=1 AND cset = 1 AND paid = 0');
}
if($operation == 'plabel')
{
    $clsname = isset($_POST['clsname']) ? $_POST['clsname'] : $_GET['clsname'];
    $whereY .=' AND clsname LIKE \'%' . $clsname . '%\''. ' AND ctype = 2';
    $theurl .= "&clsname=$clsname";
    $plabel_arrs = db::getAll(DB_TABLEPRE . 'products_cls', '*', 'ctype = 1  AND cset = 1 AND paid = 0');
    foreach($plabel_arrs as $val)
    {
        $plabel_arrs2[$val['clsid']] = $val['clsname'];
    }
}
 
//分页设置
$theurlp = $theurl; 
$thePage = isset($_GET['page']) ? $_GET['page'] : 1;
$per = 4;
$theurl .= "&page=$thePage";

//下面是集中操作
$actionU = isset($_POST['actionU']) ? $_POST['actionU'] : "";
//参数设定
switch ($operation)
{
case 'news':
    $tableU = DB_TABLEPRE . 'news';
    $idkeyU = 'nid';
    break; 
case 'products':
    $tableU = DB_TABLEPRE . 'products';
    $idkeyU = 'pid';
    break; 
case 'user':
    $tableU = DB_TABLEPRE . 'user_basic';
    $idkeyU = 'userid';
    break; 
case 'pcls':
    $tableU = DB_TABLEPRE . 'products_cls';
    $idkeyU = 'clsid';
    break; 
case 'plabel':
    $tableU = DB_TABLEPRE . 'products_cls';
    $idkeyU = 'clsid';
    break; 

default:;
}
 
//删除多篇
if ($actionU == "delIn")
{
    $order = isset($_POST['order']) ? $_POST['order'] : 0;
    $keyid = isset($_POST['keyid']) ? $_POST['keyid'] : 0;
    !$order && func::showMsg('选择不能为空', '../');
    //特殊性处理

/*   if ($operation=='news')
    {
        $tableU = DB_TABLEPRE . 'news';
        $idkeyU = 'nid';
    } 
    if ($operation=='products')
    {
        $tableU = DB_TABLEPRE . 'products';
        $idkeyU = 'pid';
    } 
    /*/
    $keyIn = implode(",", $order);
   // $keycount = count($keyIn); 
    if ($operation)
    {
        $isOk = db::deleteRs($tableU, "$idkeyU IN ($keyIn)");
    }
    $isOk && func::showMsg('删除成功 , 返回刷新可见结果', '../');
}
 
 
//操作查询
if ($operation)
{
    $rslist = db::getLimit( $tableU, '*', " $whereY ORDER BY $orderbySql $idkeyU DESC", $thePage, $per);
    $count = db::getCount($tableU, $idkeyU, $whereY);
    $rslist = func::subArray($rslist, 16, $idkeyU);
    $rslist = func::htmlspecialcharsArray($rslist);
    !$count && $count=0;
    $page = func::pageStr($count, $thePage, $per, $theurlp);
}
 
?>
